home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / lanuts.arc / RXM.ASM < prev    next >
Assembly Source File  |  1991-10-30  |  8KB  |  299 lines

  1.  INCLUDE \ASM\INCLUDE\BIOS.INC
  2. INCLUDE DEFS.INC
  3.  
  4. MSG_OFFS EQU    66            ; position of message text in buffer
  5. BIOS_SEG EQU    0040h            ; seg address of BIOS data area
  6. KBD_HEAD EQU    01Ah            ; offset of keyboard head ptr
  7. KBD_TAIL EQU    01Ch            ; offset of keyboard tail ptr
  8. MEM_FLAG EQU    072h            ; POST flag for rebooting
  9.  
  10. LOGOUT_SERVICE    EQU    80h
  11. RUN_SERVICE    EQU    81h
  12. REBOOT_SERVICE  EQU    82h
  13.  
  14. msv    SEGMENT
  15.     ASSUME  CS:msv
  16.     ASSUME  DS:msv
  17.     ASSUME  ES:msv
  18.     ASSUME  SS:NOTHING
  19.     ORG    0
  20. SEG_ORG    EQU    $    
  21.     ORG    100h
  22. main    PROC    FAR
  23. start:    jmp    init            ; Do initialization section
  24.  
  25. ;*******************************************************************
  26. ; LANOS VECTOR TSR portion of Resident Extensions
  27. ; The LANOS portion simply sets a message received flag and
  28. ; exits, leaving the actual processing of the message to an
  29. ; interrupt.
  30. ;*******************************************************************
  31. MSV_entry:    jmp first            ; skip data area
  32. msg_flag    db    0
  33. kbd_busy    db    0            ; still stuffin' that buffer
  34. kbd_index    dw    0            ; current position in string
  35. msg_state    db    0            ; storage for old msg flag
  36. msg_address     dd    ?            ; message address data
  37. old_msr        dd    ?            
  38. old_vector2     dd    ?            ; old DOS service vector
  39.  
  40. old_stk_seg    dw      ?                  ; Calling program's stack info
  41. old_b_ptr    dw    ?
  42. old_stk_ptr    dw      ?
  43. new_stk_seg    dw      ?
  44. new_stk_ptr    dw    OFFSET TOS
  45.         dw    60 dup (?)        ; local stack data area
  46. TOS        equ    $        
  47.  
  48. ;************************************************************************
  49. ; Start of actual LANOS message handler. This message handler should
  50. ; be loaded last.
  51. ;************************************************************************
  52. first:  
  53.     push    ax            ; save the regs we're gonna use
  54.     mov    word ptr cs:msg_address,bx    ; save address of incoming message
  55.     mov    word ptr cs:msg_address + 2,es
  56.     
  57.     mov    al,es:[bx]+1        ; get the MB_type field
  58.     cmp    al,80h            ; is it for us?
  59.     jl      END_MSH            ; if less than 80h it's not ours
  60.     
  61.     mov    cs:msg_flag,al        ; save the message type.
  62.     pop    ax                      ; restore ax
  63.     iret                ; back to originally scheduled program
  64.     
  65. END_MSH:
  66.     pop    ax            ; restore AX register
  67.     jmp    cs:old_msr              ; call everyone else...
  68.  
  69. ;*****************************************************************************
  70. ; Interrupt E0 handler --- this is apparently something that LANtastic uses
  71. ; internally to indicate when DOS is safe.
  72. ;*****************************************************************************
  73. INT_E0             DD   0
  74. DOSFREE:
  75.     PUSHF
  76.     CALL CS:old_vector2                 ; give everyone else a chance...
  77.     
  78.     push ax                ; save the regs we're using
  79.     push dx
  80.     mov    al,cs:msg_flag            ; get message flag
  81.  
  82.     cmp  al,0                           ; have our services been requested?
  83.     jz   Done_E0            ; If not, skip this stuff
  84.  
  85. CHK_LOGOUT:
  86.     cmp    al,LOGOUT_SERVICE        ; is it a logout request?
  87.     jne    CHK_RUN                ; if not, continue
  88.     
  89.     call logout                ; execute the logout
  90.     mov     cs:msg_flag,0            ; reset the message flag
  91.     jmp  Done_E0            ; all done.
  92.     
  93. CHK_RUN:
  94.     cmp al,RUN_SERVICE            ; is it a remote RUN request?        
  95.     jne CHK_REBOOT
  96.     
  97.     cmp    cs:kbd_busy,0            ; are we already stuffing the buffer?
  98.     jnz    DO_RUN
  99.  
  100.     inc    cs:kbd_busy            ; set the busy flag
  101.     mov    cs:kbd_index,66            ; set our string pointer to the text.
  102.     
  103. DO_RUN:
  104. ; Note -- stuff_buffer is responsible for clearing msg_flag and kbd_busy when
  105. ; it has stuffed all the characters into the buffer and added a carriage 
  106. ; return
  107.  
  108.     call stuff_buffer            ; Enter a character into der buffer.
  109.     jmp    Done_E0
  110.     
  111. CHK_REBOOT:
  112.     cmp al,REBOOT_SERVICE        ; is it a reboot request?
  113.     jne Done_E0                ; if it's not for us, continue
  114.     
  115. ; reboot der computer now!
  116.     mov    ax,BIOS_SEG
  117.     mov    ds,ax            
  118.     mov ax,1234h
  119.     mov WORD PTR ds:[MEM_FLAG],ax      ; set keyboard reboot flag
  120.     pushf                ; set up for hard reboot
  121.     mov    ax,0FFFFh
  122.     push ax
  123.     xor  ax,ax
  124.     push ax
  125.     retf
  126.  
  127. Done_E0:
  128.    pop  dx
  129.    pop    ax
  130.    iret
  131.     
  132. ;*****************************************************************************
  133. ; Logs the computer out of the specified server 
  134. ;*****************************************************************************
  135. logout    PROC    near
  136.         push    di
  137.         push    ax
  138.         push    es
  139.     
  140.     mov    di,word ptr cs:msg_address    ; put server name in ES:DI
  141.     add     di,MSG_OFFS                    ; point to message text
  142.     mov    ax,word ptr cs:msg_address+2
  143.     mov    es,ax
  144.     
  145.     mov    ax,5F82h        ; log out of the server
  146.     int    21h            ; do it!
  147.  
  148.     pop    es
  149.     pop    ax
  150.     pop    di
  151.     
  152.         ret
  153. logout    ENDP
  154.     
  155. ;*****************************************************************************
  156. ; Stuffs the specified command in the keyboard buffer, one key at a time.
  157. ;  
  158. ;*****************************************************************************
  159. Stuff_Buffer PROC    near 
  160.     @NewStack
  161.     cli                    ; forbid interrupts
  162.     
  163. ; Point DS to our command string buffer
  164.     mov    ax,word ptr cs:msg_address+2    ; point data segment to msg buffer
  165.     mov    ds,ax
  166.     
  167.     mov     si,word ptr cs:msg_address
  168.     add     si,cs:kbd_index                 ; get our offset
  169.  
  170.     mov    al,byte ptr ds:[si]        ; get the next character
  171.     
  172.     cmp    al,0                ; is it the terminator
  173.     jnz    Start_Stuff            ; if not, continue
  174.  
  175.     mov    cs:kbd_busy,0            ; clear keyboard busy flag
  176.     mov    cs:msg_flag,0            ; clear message flag
  177.     mov    al,13                ; convert char to return
  178.  
  179. ; point ES to the BIOS data area
  180. Start_Stuff:
  181.     mov     bx, BIOS_SEG    
  182.     mov     es, bx
  183.     
  184.     mov     bx, word ptr es:[KBD_TAIL]    ; is anything in the buffer?
  185.     cmp    bx, word ptr es:[KBD_HEAD]        
  186.     jnz    Done_Stuff            ; if so, then don't do anything
  187.  
  188.     inc    cs:kbd_index            ; point to the next char
  189.     
  190.     mov    es:[bx],ax            ; save the keystroke
  191.     inc    bx
  192.     inc    bx                ; move the tail pointer
  193.     cmp    bx,3Eh                ; check for buffer wrap
  194.     jl    Set_Kbd_Ptrs            ; have we wrapped?
  195.     mov    bx,1Eh                ; if so, back to start of buffer
  196. Set_Kbd_Ptrs:
  197.     mov    word ptr es:[KBD_TAIL],bx    ; set the keyboard buffer ptr.
  198.     
  199. Done_Stuff:
  200.      @OldStack    
  201.     ret
  202. Stuff_Buffer    ENDP    
  203.  
  204. LAST_BYTE    EQU $
  205.  
  206. ;
  207. ;    Initialization -- thrown away after load
  208. ;
  209.  
  210. ;*********************************************************************
  211. ; Subroutines
  212. ;********************************************************************
  213. PRT_STR    PROC    NEAR
  214. ;
  215. ; Write ASCIIZ string pointed to by ES:DI at current cursor position
  216. ;
  217. L3:
  218.     mov    al,es:[di]        ; get the character
  219.     or    al,al            ; See if it's a zero
  220.     jz    L4            ; Yes- we're done
  221.     mov    bx,7            ; display page 0, fg color 7
  222.     mov     ah,0Eh            ; Write char / tty mode
  223.     int     10h            ; Display the character
  224.     inc    di            ; get the next char
  225.     jmp    short L3
  226. L4:
  227.     ret    
  228. PRT_STR    ENDP
  229.  
  230.  
  231.  
  232. title1    db    "    SoftMagic Resident Extension Module V1.0 for LANtastic",13,10,0
  233. title2    db    "Copyright 1990 by SoftMagic, Inc. All rights Reserved.",13,10,0
  234. title3    db    "     LANtastic is a trademark of Artisoft, Inc.",13,10,0
  235.  
  236. IFDEF    SHAREWARE
  237. title5  db      7,"Thanks for trying this unregistered ShareWare Version!",7,7,13,10,0
  238. ENDIF
  239.  
  240. init:
  241.     @NewStack            ; Set up local stack
  242.     push     cs
  243.     pop    es
  244.  
  245. ; Display title messge
  246.     mov     di,OFFSET title1
  247.     call    PRT_STR
  248.     mov    di,OFFSET title2
  249.     call    PRT_STR
  250.     mov    di,OFFSET title3
  251.     call     PRT_STR
  252.     
  253. IFDEF    SHAREWARE    
  254.     mov    di,OFFSET title5
  255.     call    PRT_STR
  256. ENDIF    
  257.  
  258. ; Get old LANOS message handler vector
  259.     mov     ax,5FE2h
  260.     int    21h
  261.     mov    word ptr old_msr,bx     ; Save the location of the old vector
  262.     mov    word ptr old_msr+2,es
  263.  
  264. ;
  265. ; Replace the LANOS message service
  266. ;
  267.     mov    ax,cs
  268.     mov    es,ax
  269.     mov    ax,5FE3h
  270.     mov    bx,OFFSET MSV_entry
  271.     int    21H
  272.  
  273. ;
  274. ; Replace LANtastic's internal DOS free vector
  275. ;
  276.     MOV  AX,5FE0H
  277.     INT  21H                            ; GET THE DOS FREE VECTOR
  278.     MOV  WORD PTR old_vector2,BX
  279.     MOV  WORD PTR old_vector2+2,ES
  280.  
  281. ;
  282. ; Set vector to our routine
  283. ;
  284.     push cs
  285.     pop  es    
  286.         MOV  BX,OFFSET DOSFREE
  287.         MOV  AX,5FE1H
  288.         INT  21H                           
  289.  
  290. ; Terminate and stay resident
  291.      @OldStack            ; Restore caller's stack
  292.      mov    dx,(offset LAST_BYTE - SEG_ORG + 15) shr 4
  293.      mov    ah,31h                  ; free memory and leave
  294.      int     21h
  295. main    ENDP
  296. msv    ENDS
  297. END    start                        
  298.                     
  299.